<template>
  <div>
    <el-container>
      <el-header height="70px">
        <p class="header_title">会员列表</p>
        <!--  -->
        <el-breadcrumb separator="/">
          <el-breadcrumb-item>会员维护</el-breadcrumb-item>
          <el-breadcrumb-item>会员列表</el-breadcrumb-item>
          <el-breadcrumb-item></el-breadcrumb-item>
        </el-breadcrumb>
      </el-header>

      <el-main>
        <el-card class="box-card">
          <div slot="header">
            <span>会员列表</span>
          </div>

          <el-row :gutter="20">
            <el-col :span="4">
               <el-button type="primary" class="add"
                @click="addDialogVisible = true">添加</el-button>
            </el-col>
             <el-col :span="10">
                <b class="sum_data">数据总数：</b>
               <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pagination.pagenum"
                :page-size="pagination.pagesize"
                 :page-sizes="[3, 5, 10, 20]"
                layout="total, sizes"
                :total="pagination.total"
                class="top_nav">
               </el-pagination>
            </el-col>
            
          </el-row>
         

          <!-- 表格 -->
          <el-table :data="pagelist" style="width: 100%" border stripe>
            <el-table-column label="头像" width="60px" prop="image">
              <template slot-scope="scope">
                <el-image
                  :src="scope.row.image"
                  style="width:50px;height:50px"
                  fit="cover"
                ></el-image>
              </template>
            </el-table-column>
            <el-table-column prop="username" label="用户名" width="140px">
            </el-table-column>
            <el-table-column prop="id" label="手机号" width="160px">
            </el-table-column>
            <el-table-column prop="date" label="注册时间" width="160px">
            </el-table-column>
            <el-table-column prop="name" label="会员类型" width="120px">
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button type="warning" size="mini">生成二维码</el-button>
                <el-button type="primary" size="mini">拉新统计</el-button>
                <el-button type="success" size="mini">业绩统计</el-button>
              </template>
            </el-table-column>
          </el-table>

          <!-- 分页 -->
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pagination.pagenum"
            :page-size="pagination.pagesize"
            background
            layout="prev, pager, next"
            :total="pagination.total"
          >
          </el-pagination>
        </el-card>
      </el-main>
    </el-container>

    <!-- 添加对话框 -->
    <el-dialog
      title="添加行为信息"
      :visible.sync="addDialogVisible"
      width="40%"
      @close="addDialogClosed"
    >
      <el-form
        :model="addForm"
        :rules="addFormRules"
        ref="addFormRef"
        label-width="70px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户" prop="uid">
          <el-input v-model="addForm.uid" type="number"></el-input>
        </el-form-item>
        <el-form-item label="VIP" prop="vid">
          <el-input v-model="addForm.vid" type="number"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="onSubmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      vipUserInfo: {
        userVips: "",
        total: "",
      },
      vipUserlist: [],
      pagination: {
        // 当前页数
        pagenum: 1,
        // 页面显示多少条数据
        pagesize: 5,
        // 总数
        total: 2,
      },
      pagelist: [],
      addDialogVisible:false,
      addForm:{
        uid:"",
        vid:""
      },
      addFormRules: {
        vid: [{ required: true, message: "请输入数值", trigger: "blur" }],
        uid: [{ required: true, message: "请输入数值", trigger: "blur" }]
      },
    };
  },
  methods: {
    async getUserList() {
      const res = await this.http.get("/uservip/select", this.pagination);
      this.pagelist = res.userVips;
      this.pagination.total = res.total;
      console.log(res);
    },
    // 监听pagesize的改变
    handleSizeChange(newSize) {
      // console.log(newSize);
      this.pagination.pagesize = newSize;
      this.getUserList();
    },
    // 监听 页码值 改变
    handleCurrentChange(newPage) {
      // console.log(newPage);
      this.pagination.pagenum = newPage;
      this.getUserList();
    },
       addDialogClosed() {
      this.$refs.addFormRef.resetFields();
    },
    // 添加行为
    onSubmit() {
      this.$refs.addFormRef.validate(async (valid) => {
        if (!valid) return;
        // 发起添加网络请求
        const  { res }  = await this.http.post("/uservip/add", this.addForm);
        // console.log(res);

        if (status !== 400) {
          this.$message.error("添加行为失败");
        }
        this.$message.success("添加行为成功");
        this.addDialogVisible = false;
        this.getUserList();
      });
    },

  },
  created() {
    this.getUserList();
  },
};
</script>

<style scoped></style>
